﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;


namespace FileListBuilder
{
    [DataContract]
    public class Document
    {
        public Document(string sCompleteFileName,Options options)
        {
            try
            {
                CompleteFileName = "file:///" + sCompleteFileName;
                Directory = Path.GetDirectoryName(sCompleteFileName);
                FileName = Path.GetFileName(sCompleteFileName);
                string[] splitCodeAndFileName = FileName.Split(options.CodeSeparator);
                string[] splitCode = splitCodeAndFileName[0].Split(options.TagSeparator);
                Type = splitCode[0];
                Service = splitCode[1];
                Numero = splitCode[2];
                Version = splitCode[3];

                Title = Path.GetFileNameWithoutExtension(splitCodeAndFileName[1]);
            }
            catch (Exception ex)
            {
                Program.NumberOfFileNOK++;
                Program.Log(-1, String.Format("Bad filename format. [{0}]", sCompleteFileName), options);
            }
        }

        [DataMember]
        public string Type {get;set;}
        [DataMember]
        public string Service { get; set; }
        [DataMember]
        public string Numero { get; set; }
        [DataMember]
        public string Version { get; set; }
        [DataMember]
        public string Title { get; set; }
        [DataMember]
        public string CompleteFileName { get; set; }
        [DataMember]
        public string FileName { get; set; }
        [DataMember]
        public string Directory { get; set; }
    }
}
